package com.teamwhole.modules.grid.web;

import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.pagehelper.Page;
import com.google.common.collect.Maps;
import com.teamwhole.common.model.ResultInfo;
import com.teamwhole.modules.grid.entity.SquareActivity;
import com.teamwhole.modules.grid.service.SquareActivityService;

@Component
@Path("grid/squareActivity")
@Consumes("application/json;charset=utf-8")
@Produces("application/json;charset=utf-8")
public class SquareActivityResource {

	@Autowired
	private SquareActivityService squareActivityService;
	
	@Path("get")
	@GET
	public SquareActivity get(@QueryParam("id") String id) {
		return squareActivityService.get(id);
	}
	
	@Path("list")
	@POST
	public Object list(SquareActivity entity) {
		Page<SquareActivity> page = squareActivityService.findPage(entity);
		Map<String,Object> map = Maps.newHashMap();
		map.put("total", page.getTotal());
		map.put("rows", page.getResult());
		return map; 
	}
	
	@Path("create")
	@POST
	public ResultInfo create(SquareActivity entity) {
		squareActivityService.save(entity);
		return ResultInfo.ok();
	}
	
	@Path("update")
	@POST
	public ResultInfo update(SquareActivity entity) {
		squareActivityService.save(entity);
		return ResultInfo.ok();
	}
	
	@Path("delete")
	@GET
	public ResultInfo delete(@QueryParam("id") String id) {
		squareActivityService.delete(id);;
		return ResultInfo.ok();
	}
}
